﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE_CruzDelSur;
using System.Data.SqlClient;
using System.Data;
using BR_CruzDelSur.Interfaces;

namespace BR_CruzDelSur
{
    public class BR_Vehiculo : IBR_Vehiculo
    {
        Conexion conn = new Conexion();

        public List<BE_Vehiculo> f_ListarVehiculos(int idRuta, string fecOrigen, string fecDestino, int idProgramacionRuta)
        {
            List<BE_Vehiculo> lst = new List<BE_Vehiculo>();
            SqlParameter[] param = new SqlParameter[4];
            param[0] = new SqlParameter("INT_CODIGO_RUTA", SqlDbType.Int);
            param[0].Value = idRuta;
            param[0].Direction = ParameterDirection.Input;
            param[1] = new SqlParameter("VCH_FEC_ORIGEN", SqlDbType.VarChar);
            param[1].Value = fecOrigen;
            param[1].Direction = ParameterDirection.Input;
            param[2] = new SqlParameter("VCH_FEC_DESTINO", SqlDbType.VarChar);
            param[2].Value = fecDestino;
            param[2].Direction = ParameterDirection.Input;
            param[3] = new SqlParameter("INT_CODIGO_PROGRAMACION_RUTA", SqlDbType.Int);
            param[3].Value = idProgramacionRuta;
            param[3].Direction = ParameterDirection.Input;


            DataSet ds = SqlHelper.ExecuteDataSet(conn.CadenaConexion, System.Data.CommandType.StoredProcedure, "SP_BUSCARVEHICULOS", param);

            foreach (DataRow item in ds.Tables[0].Rows)
            {
                lst.Add(new BE_Vehiculo()
                {
                    TipoTransporte = item["VCH_TIPO_TRANSPORTE"].ToString(),
                    Origen = item["VCH_ORIGEN"].ToString(),
                    Color = item["VCH_COLOR"].ToString(),
                    Modelo = item["VCH_MODELO"].ToString(),
                    Marca = item["VCH_MARCA"].ToString(),
                    Placa = item["VCH_PLACA"].ToString(),
                    Codigo = Convert.ToInt16(item["INT_VEHICULO"].ToString())
                });
            }

            return lst;
        }
    }
}
